/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: kfa_player.h
 *
 * Purpose: implementation a player  
 *
 * Developer:
 *   wen.gu , 2022-03-04
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __KFA_PLAYER_H__
#define __KFA_PLAYER_H__
#include <string>
#include <stdio.h>
#include <functional>
#include <list>
#include <mutex>
#include <thread>
#include <condition_variable>

#include "kfa_types.h"

#include "kfa_demux.h"
#include "kfa_decoder.h"
#include "kfa_render.h"
/******************************************************************************
 **    MACROS
 ******************************************************************************/
#define MAX_BUF_QUEUE_CNT (4)
/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/

/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/

class KfaPlayer
{
public:
    KfaPlayer();
    ~KfaPlayer();

public:
    bool setDataSource(const std::string& file_url);
    bool setPlayerParameter(const render_param& param);
    bool setDisplaySize(uint32_t pos_x, uint32_t pos_y, uint32_t width, uint32_t height);
    bool start();
    bool stop();
    bool is_playing();
protected:
    void onRender();
    void onDecode();
    void onPlay();
private:
    bool is_running_ = false;
    bool is_playing_ = false;
    uint32_t display_pos_x_ = 0;
    uint32_t display_pos_y_ = 0;
    uint32_t display_width_ = 0;
    uint32_t display_height_ = 0;
    uint64_t max_dec_time_ = 0;
    uint64_t max_disp_time_ = 0;
    uint32_t show_cnt_ = 0;
    uint32_t max_dec_idx_ = 0;
    std::thread* play_thd_ = nullptr;
    //std::thread* render_thd_ = nullptr;
    KfaDemux demux_;
    KfaDecoder* decoder_ = nullptr;

    render_param render_param_;
    kfa_header header_;
    KfaRender* render_ = nullptr;
};






#endif /** !__KFA_PLAYER_H__ */

